# Makefile for running TCL scripts for Check_In_Generated_Outputs tutorial

# Variables for scripts and output directories
SCRIPTS_DIR := scripts
TOP_PRJ_SCRIPT := build_top_prj_mode.tcl
TOP_NON_PRJ_SCRIPT := build_top_non_prj_mode.tcl
SOURCES_DIR := sources
BD_XCI_PRJ := vivado_prj_xci_bd

# Targeted directories for various build outputs
BD_XCI_PRJ_RUNS := $(SOURCES_DIR)/$(BD_XCI_PRJ)/$(BD_XCI_PRJ).runs
BD_XCI_PRJ_CACHE := $(SOURCES_DIR)/$(BD_XCI_PRJ)/$(BD_XCI_PRJ).cache
BD_XCI_PRJ_HW := $(SOURCES_DIR)/$(BD_XCI_PRJ)/$(BD_XCI_PRJ).hw
BD_XCI_PRJ_SIM := $(SOURCES_DIR)/$(BD_XCI_PRJ)/$(BD_XCI_PRJ).sim
BD_XCI_PRJ_IP_USER_FILES := $(SOURCES_DIR)/$(BD_XCI_PRJ)/$(BD_XCI_PRJ).ip_user_files

# Output directories for project modes
TOP_PRJ_OUTPUT := vivado_prj_top
TOP_NON_PRJ_OUTPUT := vivado_non_prj_top

# Target for assembling top in project mode
top_prj:
	@mkdir -p $(TOP_PRJ_OUTPUT)
	@echo "Running assembly of top in project mode..."
	@echo "Output directory created: $(TOP_PRJ_OUTPUT)"
	cd $(TOP_PRJ_OUTPUT) && vivado -mode batch -source ../$(SCRIPTS_DIR)/$(TOP_PRJ_SCRIPT) -tclargs . -work $(TOP_PRJ_OUTPUT)

# Target for assembling top in non-project mode
top_non_prj:
	@mkdir -p $(TOP_NON_PRJ_OUTPUT)
	@echo "Running assembly of top in non-project mode..."
	@echo "Output directory created: $(TOP_NON_PRJ_OUTPUT)"
	cd $(TOP_NON_PRJ_OUTPUT) && vivado -mode batch -source ../$(SCRIPTS_DIR)/$(TOP_NON_PRJ_SCRIPT) -tclargs . -work $(TOP_NON_PRJ_OUTPUT)

# Target to run all modes
all: top_prj top_non_prj
	@echo "Completed all builds: assembly of top in project and non-project modes."

# Clean target to remove generated directories and files
clean:
	@rm -rf $(TOP_PRJ_OUTPUT) $(TOP_NON_PRJ_OUTPUT) \
	$(BD_XCI_PRJ_RUNS) $(BD_XCI_PRJ_CACHE) $(BD_XCI_PRJ_HW) \
	$(BD_XCI_PRJ_SIM) $(BD_XCI_PRJ_IP_USER_FILES) \
	$(SOURCES_DIR)/$(BD_XCI_PRJ)/*.log \
	$(SOURCES_DIR)/$(BD_XCI_PRJ)/*.jou
	@echo "Cleaned output directories: $(TOP_PRJ_OUTPUT), $(TOP_NON_PRJ_OUTPUT), $(BD_XCI_PRJ_RUNS), $(BD_XCI_PRJ_CACHE), $(BD_XCI_PRJ_HW), $(BD_XCI_PRJ_SIM), $(BD_XCI_PRJ_IP_USER_FILES), $(SOURCES_DIR)/$(BD_XCI_PRJ)/*.log, $(SOURCES_DIR)/$(BD_XCI_PRJ)/*.jou"

